import *as API from '../../api/index'
const state={
    searchData:[],
    titleArr:[],
    tenData:[],
    searchItem:"",
    refrshData:[]
}

const mutations={  // 同步
    getData(state,res){
        state.searchData = res 
    },
    getArr(state,res){
        state.titleArr.push(res)
        // console.log(state.titleArr)
    },
    gettendata(state,res){
        // console.log(res.info.splice(0,10))
        state.tenData = res.info.splice(0,10).sort((a,b)=>{return   b.see_num -  a.see_num})
        // console.log(state.tenData)
    },
    getsearchItem(state,res){
        state.searchItem = res 
    },
    getRefrshData(state,res){
        state.refrshData = res
    }
}

const actions={   // 异步
     getSearchData({commit},data){
            commit('getData',data)
     },
     getTitleArr({commit},title){
         commit('getArr',title)
     },
     getTenData({commit},i){
         API.getBookList().then(res=>{
             commit('gettendata',res)
         })
     }
}
const getters={  //计算属性
   
}
export default {
    namespaced:true,
    state,
    getters,
    mutations,
    actions
}
